﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TSAP02
    {
        public TSAP02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAPKOPF();
            DataContext = MV;
            MESSAGES += "CHKFLOW;";
            InitializeComponent();
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }

        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
                case "CHKFLOW":
                    CHKFLOW();
                    break;
            }
        } 
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            LOADALL();
        }
        public void CHKFLOW()
        {
        }
        public override void LOADALL()
        {

            dwData = TBMain.NewRow();
            dwData["APKMANDANT"] = app.Mandant;
            dwData["APKANRKRS"] = " AND APKANRKRS LIKE '%" + KRS + "%'";
            dwData["APKSTUFE"] = " AND APKSTUFE='" + ARTST + "'";
            SResult = TMV.QAPK03(dwData);

            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                row["DES"] = Helpers.Helper.GetGB2312Value(row["APKSPEZIF"].ToString()).Trim();
            }
            MergeData(SResult, false);
        }
        public override void LOADBYAUF()
        {  
            Locate("KEY", ORDERNUM);
        }
        public override void OnARTSTChg()
        {
            base.OnARTSTChg();
        }
        public override void OnEXAUFChg(string vlaue)
        {
            if (EXAUF.Length < 1)
                return;
            dwData = TBMain.NewRow();
            dwData["APKMANDANT"] = app.Mandant;
            dwData["APKSTUFE"] = " AND APKSTUFE='" + EXAUF.Substring(0, 1) + "'";
            SResult = TMV.QAPK03(dwData);

            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                row["DES"] = Helpers.Helper.GetGB2312Value(row["APKSPEZIF"].ToString()).Trim();
            }
            MergeData(SResult, false);
            base.OnEXAUFChg(vlaue);
        }
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                LOADALL();
            }
            base.ManageCommand(sender, e);
        }
        //规则变化时候，根据规则进行选择      

    }

}
